package com.dragon.mmochat.util;

import java.util.ArrayList;
import java.util.List;

import com.dragon.mmochat.MmochatConstant;
import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.widget.TLVStructure;
import com.skymobi.util.Text;

public class CreateMsgBoxTLVWithBmp extends TLVStructure {

	private int bmpId;
	private String leftName = "";
	private String rightName = "";
	private String title = "提示";
	private Text content;
	private List<TLVStructure> leftTLVs;
	private List<TLVStructure> rightTLVs;

	public int getBmpId() {
		return bmpId;
	}

	public void setBmpId(int bmpId) {
		this.bmpId = bmpId;
	}

	public void setLeftName(String leftName) {
		this.leftName = leftName;
	}

	public void setRightName(String rightName) {
		this.rightName = rightName;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setContent(Text content) {
		this.content = content;
	}

	public void setLeftTLVs(List<TLVStructure> leftTLVs) {
		this.leftTLVs = leftTLVs;
	}

	public void setRightTLVs(List<TLVStructure> rightTLVs) {
		this.rightTLVs = rightTLVs;
	}

	public void addLeftTLV(TLVStructure tlv) {
		if (leftTLVs == null)
			leftTLVs = new ArrayList<TLVStructure>();
		leftTLVs.add(tlv);
	}

	public void addRightTLV(TLVStructure tlv) {
		if (rightTLVs == null)
			rightTLVs = new ArrayList<TLVStructure>();
		rightTLVs.add(tlv);
	}

	@Override
	public int getTag() {
		return MmochatConstant.createMsgboxWithBmpTag;
	}

	@Override
	public void encodeTLV(SkymobiBuffer out) {
		out.putInt(bmpId);
		out.putFixupLengthString(leftName, 4);
		out.putFixupLengthString(rightName, 4);
		out.putPrefixedString(title, 2);
		content.encode(out);
		out.putShort((short) 0);
		if (leftTLVs != null) {
			int start = out.position();
			for (TLVStructure structure : leftTLVs)
				structure.encode(out);
			out.putShort(start - 2, (short) (out.position() - start));
		}
		out.putShort((short) 0);
		if (rightTLVs != null) {
			int start = out.position();
			for (TLVStructure structure : rightTLVs)
				structure.encode(out);
			out.putShort(start - 2, (short) (out.position() - start));
		}
	}

}
